﻿using System;

namespace class3Homework
{

    class Program
    {
     
        
        static void Main(string[] args)
        {
            geometry[] a = new geometry[10];
            for(int i=0;i<10;i++)
            {
                Random ran = new Random();
                int k = ran.Next(1, 4);
                if(k==1)
                {
                    while (true)
                    {
                        a[i] = new triangle(ran.Next(0, 10), ran.Next(0, 10), ran.Next(0, 10));
                        if(a[i].selfCheck())
                        {
                            break;
                        }
                    }
                }
                else if(k==2)
                {
                    while (true)
                    {
                        a[i] = new circle(ran.Next(0, 10));
                        if (a[i].selfCheck())
                        {
                            break;
                        }
                    }
                }
                else if(k==3)
                {
                    while (true)
                    {
                        a[i] = new square(ran.Next(0, 10));
                        if (a[i].selfCheck())
                        {
                            break;
                        }
                    }
                }
                else if(k==4)
                {
                    while (true)
                    {
                        a[i] = new rectangle(ran.Next(0, 10), ran.Next(0, 10));
                        if (a[i].selfCheck())
                        {
                            break;
                        }
                    }
                }
            }
            for (int j = 0; j < 10; j++)
            {
                Console.WriteLine("图形"+j+"是"+a[j].Name+",它的面积是:"+a[j].Area+"\r\n");
            }
            double result=0;
            for(int l=0;l<10;l++)
            {
                result = result + a[l].Area;
            }
            Console.WriteLine("所有图形总面积是:" + result);
        }
    }
}
